﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Microsoft.Services.MSBuild.Tasks.Extensions
{
    internal static class FileSystemInfoExtensions
    {
        public static int GetLevel(this FileSystemInfo instance)
        {
            if (!instance.Exists)
            {
                return -1;
            }

            DirectoryInfo currentDirectory = instance as DirectoryInfo;

            if (currentDirectory == null)
            {
                currentDirectory = ((FileInfo)instance).Directory;
            }

            int level = 0;

            for (; currentDirectory.Parent != null; currentDirectory = currentDirectory.Parent )
            {
                level++;
            }

            return level;
        }
    }
}
